package com.kai.steering.common.vo;

import com.kai.steering.exception.UimpException;
import org.springframework.http.HttpStatus;

/**
 * @ Author     ：LiuKai.
 * @ Date       ：Created in 10:43 2022-2-22
 * @ Description：响应码
 * @ Modified By：
 * @Version:
 */
public enum ReturnCode {

    SUCCESS(HttpStatus.OK, "0", "操作成功"),

    UNAUTHORIZED(HttpStatus.BAD_REQUEST, "401", "非法访问.%s"),
    NOT_PERMISSION(HttpStatus.BAD_REQUEST, "403", "没有权限.%s"),
    NOT_FOUND(HttpStatus.BAD_REQUEST, "404", "你请求的资源不存在.%s"),
    FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "500", "操作失败.");

    private HttpStatus httpStatus;
    private final String code;
    private final String msg;

    ReturnCode(HttpStatus httpStatus, final String code, final String msg) {
        this.httpStatus = httpStatus;
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public HttpStatus getHttpStatus() {
        return httpStatus;
    }

    public UimpException getException(HttpStatus status, Throwable ex, String... pram) {
        String message = (pram == null) ? this.msg : String.format(this.msg, pram);
        if (status == null) {
            status = this.httpStatus;
        }
        return new UimpException(status, this.code, message, ex);
    }

    public UimpException getException(Throwable ex, String... pram) {
        return getException(null, ex, pram);
    }

    public UimpException getException(String... pram) {
        return getException(null, pram);
    }


}


